package com.xinsoft.job;

import cn.hutool.core.date.DateUtil;
import com.xinsoft.service.CusPatrolPlanService;
import lombok.extern.slf4j.Slf4j;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @ClassName PatrolPlanJob
 * @Description 巡检计划生成巡检定时任务
 * @Author lijie
 * @Date 2023/6/25 9:20 星期日
 * @Version 1.0
 */
@Slf4j
@Component
@EnableScheduling
@DisallowConcurrentExecution
public class PatrolPlanJob implements Job {

    private static CusPatrolPlanService patrolPlanService;

    @Autowired
    public void setCusPatrolPlanService(CusPatrolPlanService patrolPlanService) {
        PatrolPlanJob.patrolPlanService = patrolPlanService;
    }

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        //此处可编写要定时执行的业务代码
        System.err.println("定时任务执行，当前时间：" + DateUtil.formatDateTime(new Date()));
        System.out.println("尝试获取service：-----" + patrolPlanService);
        Integer planId = (Integer)jobExecutionContext.getJobDetail().getJobDataMap().get("sourceId");
        //获取JobDetail的传参
        System.out.println("获取到的计划id为：" + jobExecutionContext.getJobDetail().getJobDataMap().get("sourceId"));
        patrolPlanService.planToTask(planId);
    }


//    /**
//     * @Author Li9527
//     * @Description 巡检计划定期生成执行
//     * @Date 2023/6/25 9:23
//     * @params
//     * @return void
//     **/
//    @Scheduled(cron = "0 0/1 * * * ?")
//    private void planToTask() {
//        // 巡检计划定期生成执行
//        patrolPlanService.planToTask(20);
//    }
}
